#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o pipefail
set -o noclobber
set -o noglob

STARTUP_DIR="$( cd "$( dirname "$0" )" && pwd )"

source ${STARTUP_DIR}/../settings.sh

KUBECTL="kubectl --context=${KUBE_CONTEXT}"

if [[ $# < 1 ]]; then
    echo "Need MODEL_VERSION"
    exit 1
fi

MODEL_VERSION=v$1

BUILD_WORKFLOW=${MODEL_SOURCE_FILES_DIR}/build-image-and-push-using-docksock-wf.json

cat $BUILD_WORKFLOW | sed \
    -e "s/%MODEL_VERSION%/${MODEL_VERSION}/" \
    -e "s/%GITHUB_USER%/${GITHUB_USER}/" \
    -e "s/%GITHUB_TOKEN%/${GITHUB_TOKEN}/" | ${KUBECTL} -n default create -f -

